home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15669 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: user1.mnsinc.com!huang
  2. From: huang@mnsinc.com (Szu-Wen Huang)
  3. Newsgroups: comp.lang.c++,comp.lang.c,comp.os.msdos.programer,comp.os.ms-windows.programmer.misc
  4. Subject: Re: fastest code
  5. Followup-To: comp.lang.c++,comp.lang.c,comp.os.msdos.programer,comp.os.ms-windows.programmer.misc
  6. Date: 7 Apr 1996 22:35:48 GMT
  7. Organization: Monumental Network Systems
  8. Message-ID: <4k9g04$4ov@news1.mnsinc.com>
  9. References: <316112A2.7D37@public.sta.net.cn> <31611AC9.7DE1@wight.hursley.ibm.com> <3162c21a.6084138@204.248.25.97> <31641DE2.31D4@halcyon.com> <31658942.99299605@204.248.25.97>
  10. NNTP-Posting-Host: user1.mnsinc.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. William E. Kempf (srwillrd@novia.net) wrote:
  14.  
  15. : Ok, my cutsy remark has confused several people, so I will explain.
  16. : In computer science, algorithms (and this will apply to the final
  17. : machine code generated by a compiler) are evaluated for speed in a
  18. : system independant way, through a formula known as Big-O notation.  So
  19. : code is not said to be faster just because it is running on a faster
  20. : machine.  The executable program may be faster, but the underlying
  21. : code may not be.  All kinds of things can effect this, such as wether
  22. : or not the compiler moves variable declarations outside of loops, etc.
  23.  
  24. Unfortunately, the big-O analysis of algorithms do not tell you of
  25. the algorithm's speed, rather, it shows the relationship between
  26. input size and execution time.  An O(n^2) algorithm may run faster
  27. than an O(n) algorithm for all practical sizes of n.
  28.  
  29. : The original question was looking for this kind of information (even
  30. : if the poster does not understand Big-O, which I don't know if he did
  31. : or not).  He wants to know what compiler will best optimize the
  32. : machine language code generated for a specific OS and computer
  33. : architecture.
  34.  
  35. Optimizations have little to do with time complexities as well.  A
  36. compiler today is not likely to change an O(n^2) algorithm into an
  37. O(n) algorithm simply by optimizing the code, though an O(n) algorithm
  38. might be optimized into an O(1) algorithm if you're talking about a
  39. truly dumb programmer ;).
  40.